// xc_lshop/recharge/index/index.js
const app = getApp()
// var actbill = require('../../../xc/model/huka')
var actbill = require('../../model/cardpro')

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    basicurl:-1,
    CustomBar: app.globalData.CustomBar,
    navval:'recharge',

  },
  xcloaddata: function (options, config) {
    console.log("config")
    console.log(config)

    if(config && config.api_yiqidaapi){
      this.setData({
        yiqidaconfig: config.api_yiqidaapi
      })
      if(config.api_yiqidaapi.status==-1){
        this.pageback()
      }
    }else{
      this.error("该功能尚未配置", true);
    }

    var that=this;
    this.getpagelist(that,1)

  },
  getpagelist(that, rest, condition) {
    if (rest == 1) {
      that.setData({ modellist: [] });
    }
    if(!condition){
      condition ={limit:100} ;
      if(that.data.value){
        condition['name']=that.data.value
      }
    }
    actbill.offset(that, rest, condition).then(function (result) {
      var updatemodel = {};
      if ((result["code"] == "over" && result["obj"]) || result["code"] == "loadmore") {
        if (result["obj"]["modellist"].length < 1 && that.data.modellist.length < 1) {

        } else if (rest == 1) {
          updatemodel["modellist"] = result["obj"]["modellist"];
        } else {
          if (result["obj"]["modellist"].length > 0) {
            updatemodel["modellist"] = that.data.modellist.concat(result["obj"]["modellist"]);
          }
        }
      }

      wx.stopPullDownRefresh();
      that.setData(updatemodel);
    }, function () {
       
    });
  },
  onChange(e){
    this.setData({
      value: e.detail,
    });

  },
  onSearch(){
     var val=this.data.value;
     var list=this.data.allmodellist;
     var newlist=[];
     if(val){
      if(list){
        for(var i in list){
           if(list[i]['g_name'].indexOf(val) != -1){
             newlist.push(list[i])
           }
        }
      }
     }else{
      newlist=list
     }
     this.setData({
       modellist:newlist
     })
  },
  onClear(){
    this.setData({
      value:"",
      modellist:this.data.allmodellist
    })
  },
  onnavclick(e){
    console.log(e)
    this.setData({
      modellist:[],
      allmodellist:[]
    })
    var val=e.currentTarget.dataset.val;
    this.setData({
      navval:val
    })

    this.getlist()
  },
  getlist(){
    var that=this;
    actbill.list(this.data.navval).then(function(res){
      console.log("res")
      console.log(res.obj.rows)
      if(res['status']==1){
        that.setData({
          allmodellist:res.obj.rows
        }) 
        that.onSearch()
      }
      
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#000000'
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  
})